<?php


/**
 * Base class that represents a query for the 'time_reports_view' table.
 *
 *
 *
 * @method DamagesTimeReportsViewQuery orderByBrandId($order = Criteria::ASC) Order by the brand_id column
 * @method DamagesTimeReportsViewQuery orderByBrandCode($order = Criteria::ASC) Order by the brand_code column
 * @method DamagesTimeReportsViewQuery orderByBrandName($order = Criteria::ASC) Order by the brand_name column
 * @method DamagesTimeReportsViewQuery orderByCarDamageId($order = Criteria::ASC) Order by the car_damage_id column
 * @method DamagesTimeReportsViewQuery orderByCarDamageDate($order = Criteria::ASC) Order by the car_damage_date column
 * @method DamagesTimeReportsViewQuery orderByInvoiceDate($order = Criteria::ASC) Order by the invoice_date column
 * @method DamagesTimeReportsViewQuery orderByNoteDate($order = Criteria::ASC) Order by the note_date column
 * @method DamagesTimeReportsViewQuery orderByLsId($order = Criteria::ASC) Order by the ls_id column
 *
 * @method DamagesTimeReportsViewQuery groupByBrandId() Group by the brand_id column
 * @method DamagesTimeReportsViewQuery groupByBrandCode() Group by the brand_code column
 * @method DamagesTimeReportsViewQuery groupByBrandName() Group by the brand_name column
 * @method DamagesTimeReportsViewQuery groupByCarDamageId() Group by the car_damage_id column
 * @method DamagesTimeReportsViewQuery groupByCarDamageDate() Group by the car_damage_date column
 * @method DamagesTimeReportsViewQuery groupByInvoiceDate() Group by the invoice_date column
 * @method DamagesTimeReportsViewQuery groupByNoteDate() Group by the note_date column
 * @method DamagesTimeReportsViewQuery groupByLsId() Group by the ls_id column
 *
 * @method DamagesTimeReportsViewQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
 * @method DamagesTimeReportsViewQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
 * @method DamagesTimeReportsViewQuery innerJoin($relation) Adds a INNER JOIN clause to the query
 *
 * @method DamagesTimeReportsView findOne(PropelPDO $con = null) Return the first DamagesTimeReportsView matching the query
 * @method DamagesTimeReportsView findOneOrCreate(PropelPDO $con = null) Return the first DamagesTimeReportsView matching the query, or a new DamagesTimeReportsView object populated from the query conditions when no match is found
 *
 * @method DamagesTimeReportsView findOneByBrandId(int $brand_id) Return the first DamagesTimeReportsView filtered by the brand_id column
 * @method DamagesTimeReportsView findOneByBrandCode(string $brand_code) Return the first DamagesTimeReportsView filtered by the brand_code column
 * @method DamagesTimeReportsView findOneByBrandName(string $brand_name) Return the first DamagesTimeReportsView filtered by the brand_name column
 * @method DamagesTimeReportsView findOneByCarDamageId(int $car_damage_id) Return the first DamagesTimeReportsView filtered by the car_damage_id column
 * @method DamagesTimeReportsView findOneByCarDamageDate(string $car_damage_date) Return the first DamagesTimeReportsView filtered by the car_damage_date column
 * @method DamagesTimeReportsView findOneByInvoiceDate(string $invoice_date) Return the first DamagesTimeReportsView filtered by the invoice_date column
 * @method DamagesTimeReportsView findOneByNoteDate(string $note_date) Return the first DamagesTimeReportsView filtered by the note_date column
 * @method DamagesTimeReportsView findOneByLsId(int $ls_id) Return the first DamagesTimeReportsView filtered by the ls_id column
 *
 * @method array findByBrandId(int $brand_id) Return DamagesTimeReportsView objects filtered by the brand_id column
 * @method array findByBrandCode(string $brand_code) Return DamagesTimeReportsView objects filtered by the brand_code column
 * @method array findByBrandName(string $brand_name) Return DamagesTimeReportsView objects filtered by the brand_name column
 * @method array findByCarDamageId(int $car_damage_id) Return DamagesTimeReportsView objects filtered by the car_damage_id column
 * @method array findByCarDamageDate(string $car_damage_date) Return DamagesTimeReportsView objects filtered by the car_damage_date column
 * @method array findByInvoiceDate(string $invoice_date) Return DamagesTimeReportsView objects filtered by the invoice_date column
 * @method array findByNoteDate(string $note_date) Return DamagesTimeReportsView objects filtered by the note_date column
 * @method array findByLsId(int $ls_id) Return DamagesTimeReportsView objects filtered by the ls_id column
 *
 * @package    propel.generator.damages.om
 */
abstract class DamagesBaseTimeReportsViewQuery extends ModelCriteria
{
    /**
     * Initializes internal state of DamagesBaseTimeReportsViewQuery object.
     *
     * @param     string $dbName The dabase name
     * @param     string $modelName The phpName of a model, e.g. 'Book'
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
     */
    public function __construct($dbName = 'vgp_damages', $modelName = 'DamagesTimeReportsView', $modelAlias = null)
    {
        parent::__construct($dbName, $modelName, $modelAlias);
    }

    /**
     * Returns a new DamagesTimeReportsViewQuery object.
     *
     * @param     string $modelAlias The alias of a model in the query
     * @param     DamagesTimeReportsViewQuery|Criteria $criteria Optional Criteria to build the query from
     *
     * @return DamagesTimeReportsViewQuery
     */
    public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof DamagesTimeReportsViewQuery) {
            return $criteria;
        }
        $query = new DamagesTimeReportsViewQuery();
        if (null !== $modelAlias) {
            $query->setModelAlias($modelAlias);
        }
        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }

    /**
     * Find object by primary key.
     * Propel uses the instance pool to skip the database if the object exists.
     * Go fast if the query is untouched.
     *
     * <code>
     * $obj  = $c->findPk(12, $con);
     * </code>
     *
     * @param mixed $key Primary key to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return   DamagesTimeReportsView|DamagesTimeReportsView[]|mixed the result, formatted by the current formatter
     */
    public function findPk($key, $con = null)
    {
        if ($key === null) {
            return null;
        }
        if ((null !== ($obj = DamagesTimeReportsViewPeer::getInstanceFromPool((string) $key))) && !$this->formatter) {
            // the object is alredy in the instance pool
            return $obj;
        }
        if ($con === null) {
            $con = Propel::getConnection(DamagesTimeReportsViewPeer::DATABASE_NAME, Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        if ($this->formatter || $this->modelAlias || $this->with || $this->select
         || $this->selectColumns || $this->asColumns || $this->selectModifiers
         || $this->map || $this->having || $this->joins) {
            return $this->findPkComplex($key, $con);
        } else {
            return $this->findPkSimple($key, $con);
        }
    }

    /**
     * Find object by primary key using raw SQL to go fast.
     * Bypass doSelect() and the object formatter by using generated code.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return   DamagesTimeReportsView A model object, or null if the key is not found
     * @throws   PropelException
     */
    protected function findPkSimple($key, $con)
    {
        $sql = 'SELECT BRAND_ID, BRAND_CODE, BRAND_NAME, CAR_DAMAGE_ID, CAR_DAMAGE_DATE, INVOICE_DATE, NOTE_DATE, LS_ID FROM time_reports_view WHERE BRAND_ID = :p0';
        try {
            $stmt = $con->prepare($sql);
            $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
            $stmt->execute();
        } catch (Exception $e) {
            Propel::log($e->getMessage(), Propel::LOG_ERR);
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
        }
        $obj = null;
        if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
            $obj = new DamagesTimeReportsView();
            $obj->hydrate($row);
            DamagesTimeReportsViewPeer::addInstanceToPool($obj, (string) $key);
        }
        $stmt->closeCursor();

        return $obj;
    }

    /**
     * Find object by primary key.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return DamagesTimeReportsView|DamagesTimeReportsView[]|mixed the result, formatted by the current formatter
     */
    protected function findPkComplex($key, $con)
    {
        // As the query uses a PK condition, no limit(1) is necessary.
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKey($key)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
    }

    /**
     * Find objects by primary key
     * <code>
     * $objs = $c->findPks(array(12, 56, 832), $con);
     * </code>
     * @param     array $keys Primary keys to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return PropelObjectCollection|DamagesTimeReportsView[]|mixed the list of results, formatted by the current formatter
     */
    public function findPks($keys, $con = null)
    {
        if ($con === null) {
            $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKeys($keys)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->format($stmt);
    }

    /**
     * Filter the query by primary key
     *
     * @param     mixed $key Primary key to use for the query
     *
     * @return DamagesTimeReportsViewQuery The current query, for fluid interface
     */
    public function filterByPrimaryKey($key)
    {

        return $this->addUsingAlias(DamagesTimeReportsViewPeer::BRAND_ID, $key, Criteria::EQUAL);
    }

    /**
     * Filter the query by a list of primary keys
     *
     * @param     array $keys The list of primary key to use for the query
     *
     * @return DamagesTimeReportsViewQuery The current query, for fluid interface
     */
    public function filterByPrimaryKeys($keys)
    {

        return $this->addUsingAlias(DamagesTimeReportsViewPeer::BRAND_ID, $keys, Criteria::IN);
    }

    /**
     * Filter the query on the brand_id column
     *
     * Example usage:
     * <code>
     * $query->filterByBrandId(1234); // WHERE brand_id = 1234
     * $query->filterByBrandId(array(12, 34)); // WHERE brand_id IN (12, 34)
     * $query->filterByBrandId(array('min' => 12)); // WHERE brand_id > 12
     * </code>
     *
     * @param     mixed $brandId The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return DamagesTimeReportsViewQuery The current query, for fluid interface
     */
    public function filterByBrandId($brandId = null, $comparison = null)
    {
        if (is_array($brandId) && null === $comparison) {
            $comparison = Criteria::IN;
        }

        return $this->addUsingAlias(DamagesTimeReportsViewPeer::BRAND_ID, $brandId, $comparison);
    }

    /**
     * Filter the query on the brand_code column
     *
     * Example usage:
     * <code>
     * $query->filterByBrandCode('fooValue');   // WHERE brand_code = 'fooValue'
     * $query->filterByBrandCode('%fooValue%'); // WHERE brand_code LIKE '%fooValue%'
     * </code>
     *
     * @param     string $brandCode The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return DamagesTimeReportsViewQuery The current query, for fluid interface
     */
    public function filterByBrandCode($brandCode = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($brandCode)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $brandCode)) {
                $brandCode = str_replace('*', '%', $brandCode);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(DamagesTimeReportsViewPeer::BRAND_CODE, $brandCode, $comparison);
    }

    /**
     * Filter the query on the brand_name column
     *
     * Example usage:
     * <code>
     * $query->filterByBrandName('fooValue');   // WHERE brand_name = 'fooValue'
     * $query->filterByBrandName('%fooValue%'); // WHERE brand_name LIKE '%fooValue%'
     * </code>
     *
     * @param     string $brandName The value to use as filter.
     *              Accepts wildcards (* and % trigger a LIKE)
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return DamagesTimeReportsViewQuery The current query, for fluid interface
     */
    public function filterByBrandName($brandName = null, $comparison = null)
    {
        if (null === $comparison) {
            if (is_array($brandName)) {
                $comparison = Criteria::IN;
            } elseif (preg_match('/[\%\*]/', $brandName)) {
                $brandName = str_replace('*', '%', $brandName);
                $comparison = Criteria::LIKE;
            }
        }

        return $this->addUsingAlias(DamagesTimeReportsViewPeer::BRAND_NAME, $brandName, $comparison);
    }

    /**
     * Filter the query on the car_damage_id column
     *
     * Example usage:
     * <code>
     * $query->filterByCarDamageId(1234); // WHERE car_damage_id = 1234
     * $query->filterByCarDamageId(array(12, 34)); // WHERE car_damage_id IN (12, 34)
     * $query->filterByCarDamageId(array('min' => 12)); // WHERE car_damage_id > 12
     * </code>
     *
     * @param     mixed $carDamageId The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return DamagesTimeReportsViewQuery The current query, for fluid interface
     */
    public function filterByCarDamageId($carDamageId = null, $comparison = null)
    {
        if (is_array($carDamageId)) {
            $useMinMax = false;
            if (isset($carDamageId['min'])) {
                $this->addUsingAlias(DamagesTimeReportsViewPeer::CAR_DAMAGE_ID, $carDamageId['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($carDamageId['max'])) {
                $this->addUsingAlias(DamagesTimeReportsViewPeer::CAR_DAMAGE_ID, $carDamageId['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(DamagesTimeReportsViewPeer::CAR_DAMAGE_ID, $carDamageId, $comparison);
    }

    /**
     * Filter the query on the car_damage_date column
     *
     * Example usage:
     * <code>
     * $query->filterByCarDamageDate('2011-03-14'); // WHERE car_damage_date = '2011-03-14'
     * $query->filterByCarDamageDate('now'); // WHERE car_damage_date = '2011-03-14'
     * $query->filterByCarDamageDate(array('max' => 'yesterday')); // WHERE car_damage_date > '2011-03-13'
     * </code>
     *
     * @param     mixed $carDamageDate The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return DamagesTimeReportsViewQuery The current query, for fluid interface
     */
    public function filterByCarDamageDate($carDamageDate = null, $comparison = null)
    {
        if (is_array($carDamageDate)) {
            $useMinMax = false;
            if (isset($carDamageDate['min'])) {
                $this->addUsingAlias(DamagesTimeReportsViewPeer::CAR_DAMAGE_DATE, $carDamageDate['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($carDamageDate['max'])) {
                $this->addUsingAlias(DamagesTimeReportsViewPeer::CAR_DAMAGE_DATE, $carDamageDate['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(DamagesTimeReportsViewPeer::CAR_DAMAGE_DATE, $carDamageDate, $comparison);
    }

    /**
     * Filter the query on the invoice_date column
     *
     * Example usage:
     * <code>
     * $query->filterByInvoiceDate('2011-03-14'); // WHERE invoice_date = '2011-03-14'
     * $query->filterByInvoiceDate('now'); // WHERE invoice_date = '2011-03-14'
     * $query->filterByInvoiceDate(array('max' => 'yesterday')); // WHERE invoice_date > '2011-03-13'
     * </code>
     *
     * @param     mixed $invoiceDate The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return DamagesTimeReportsViewQuery The current query, for fluid interface
     */
    public function filterByInvoiceDate($invoiceDate = null, $comparison = null)
    {
        if (is_array($invoiceDate)) {
            $useMinMax = false;
            if (isset($invoiceDate['min'])) {
                $this->addUsingAlias(DamagesTimeReportsViewPeer::INVOICE_DATE, $invoiceDate['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($invoiceDate['max'])) {
                $this->addUsingAlias(DamagesTimeReportsViewPeer::INVOICE_DATE, $invoiceDate['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(DamagesTimeReportsViewPeer::INVOICE_DATE, $invoiceDate, $comparison);
    }

    /**
     * Filter the query on the note_date column
     *
     * Example usage:
     * <code>
     * $query->filterByNoteDate('2011-03-14'); // WHERE note_date = '2011-03-14'
     * $query->filterByNoteDate('now'); // WHERE note_date = '2011-03-14'
     * $query->filterByNoteDate(array('max' => 'yesterday')); // WHERE note_date > '2011-03-13'
     * </code>
     *
     * @param     mixed $noteDate The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return DamagesTimeReportsViewQuery The current query, for fluid interface
     */
    public function filterByNoteDate($noteDate = null, $comparison = null)
    {
        if (is_array($noteDate)) {
            $useMinMax = false;
            if (isset($noteDate['min'])) {
                $this->addUsingAlias(DamagesTimeReportsViewPeer::NOTE_DATE, $noteDate['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($noteDate['max'])) {
                $this->addUsingAlias(DamagesTimeReportsViewPeer::NOTE_DATE, $noteDate['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(DamagesTimeReportsViewPeer::NOTE_DATE, $noteDate, $comparison);
    }

    /**
     * Filter the query on the ls_id column
     *
     * Example usage:
     * <code>
     * $query->filterByLsId(1234); // WHERE ls_id = 1234
     * $query->filterByLsId(array(12, 34)); // WHERE ls_id IN (12, 34)
     * $query->filterByLsId(array('min' => 12)); // WHERE ls_id > 12
     * </code>
     *
     * @param     mixed $lsId The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return DamagesTimeReportsViewQuery The current query, for fluid interface
     */
    public function filterByLsId($lsId = null, $comparison = null)
    {
        if (is_array($lsId)) {
            $useMinMax = false;
            if (isset($lsId['min'])) {
                $this->addUsingAlias(DamagesTimeReportsViewPeer::LS_ID, $lsId['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($lsId['max'])) {
                $this->addUsingAlias(DamagesTimeReportsViewPeer::LS_ID, $lsId['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(DamagesTimeReportsViewPeer::LS_ID, $lsId, $comparison);
    }

    /**
     * Exclude object from result
     *
     * @param   DamagesTimeReportsView $timeReportsView Object to remove from the list of results
     *
     * @return DamagesTimeReportsViewQuery The current query, for fluid interface
     */
    public function prune($timeReportsView = null)
    {
        if ($timeReportsView) {
            $this->addUsingAlias(DamagesTimeReportsViewPeer::BRAND_ID, $timeReportsView->getBrandId(), Criteria::NOT_EQUAL);
        }

        return $this;
    }

}
